<?php
namespace app\admin\controller;

use app\admin\model\Category;
use app\admin\model\Question;
use app\common\controller\Common;
use app\common\model\User as UserModel;
use think\Db;
use think\Loader;
use think\Request;
use think\captcha\Captcha;

class Jie extends Common
{
    
    public function index()
    {

    	$data = input('');

    	$where = [];

    	$start = input('start') ? strtotime(input('start')) : 0 ;

    	$end = input('end') ? strtotime(input('end'))+86400 : time() ;

    	$where['t1.ctime'] = [['>=',$start],['<=',$end]];

    	if(input('title')){
    		$where['title']=['like',"%".trim(input('title'))."%"];
    	}

    	if(input('is_top')){
    		$where['t1.is_top']= 1;
    	}

    	if(input('order')){
    		$question = Db::table('fly_question')
	        ->alias('t1')
	        ->field('t1.*,t2.face,t2.nickname,t3.cname')
	        ->join('fly_user t2','t1.uid = t2.uid')
	        ->join('fly_category t3','t1.cid=t3.cid')
	        ->order('t1.'.input('order')." ".input('type'))
	        ->where($where)
	        ->paginate(10,false,['query'=>$data]);

    	}else{
    		$question = Db::table('fly_question')
	        ->alias('t1')
	        ->field('t1.*,t2.face,t2.nickname,t3.cname')
	        ->join('fly_user t2','t1.uid = t2.uid')
	        ->join('fly_category t3','t1.cid=t3.cid')
	        ->where($where)
	        ->paginate(10,false,['query'=>$data]);
    	}
         
        
        $this->assign('data',$data);
    	$this->assign('cates',Category::all());
    	$this->assign('question',$question);
   		return $this->fetch();
    }

    public function changepass()
    {

    	var_dump(input(''));
    	return $this->fetch();
    }

    public function status()
    {
    	$data = input('post.');

    	// $this->error("你没有权限,请联系超级管理员开通");
    	// 
    	$user = UserModel::get($data['uid']);

    	if($data['status']=='true'){
    		$user->status = 0;
    		$user->save();
    	}else{
    		$user->status = 1;
    		$user->save();
    	}

    	$this->success('变更成功');
    }

}